import cv2
import numpy as np
img=cv2.imread("images/a.jpg")
logo=cv2.imread("images/logo.jpg")

logo_h=logo.shape[0]
logo_w=logo.shape[1]

gray=cv2.cvtColor(logo,cv2.COLOR_BGR2GRAY)#转为灰度图
ret,mask1=cv2.threshold(gray,175,255,cv2.THRESH_BINARY_INV)#二值化
cv2.imshow("a",mask1)
print("mask======= ",mask1[2][2])

logo_temp=cv2.bitwise_and(logo,logo,mask=mask1);
cv2.imshow("b",logo_temp)
rio=img[0:logo_h,0:logo_w]# y1,y2  x1  x2
mask1_inv=cv2.bitwise_not(mask1)
cv2.imshow("c",mask1_inv)

rio_temp=cv2.bitwise_and(rio,rio,mask=mask1_inv)
cv2.imshow("d",rio_temp)
dst=cv2.add(logo_temp,rio_temp)
img[0:logo_h,0:logo_w]=dst
cv2.imshow("img",img)

cv2.waitKey(0)